package br.com.locadora.frame;

import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

/**
 *
 * @author JavaJacques
 */
public class Principal extends javax.swing.JFrame {

    public Principal() {
        initComponents();
        setExtendedState(MAXIMIZED_BOTH);
        setDefaultCloseOperation(Principal.DO_NOTHING_ON_CLOSE);
        URL url = this.getClass().getResource("/icones/bobina.png");
        Image imagemTitulo = Toolkit.getDefaultToolkit().getImage(url);
        this.setIconImage(imagemTitulo);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        arvore = new javax.swing.JTree();
        jToolBar1 = new javax.swing.JToolBar();
        btnGerarBase = new javax.swing.JButton();
        btnFuncionario = new javax.swing.JButton();
        btnDependente = new javax.swing.JButton();
        btnClientes = new javax.swing.JButton();
        btnCategoria = new javax.swing.JButton();
        btnCd = new javax.swing.JButton();
        btnDvd = new javax.swing.JButton();
        btnGames = new javax.swing.JButton();
        btnPagamentoAntecipado = new javax.swing.JButton();
        btnLocacao = new javax.swing.JButton();
        btnSair = new javax.swing.JButton();
        menu_principal = new javax.swing.JMenuBar();
        menu_arquivo = new javax.swing.JMenu();
        sub_sair = new javax.swing.JMenuItem();
        menu_tabelas = new javax.swing.JMenu();
        sub_gerarBase = new javax.swing.JMenuItem();
        menu_cadastros = new javax.swing.JMenu();
        sub_categoria = new javax.swing.JMenuItem();
        sub_cliente = new javax.swing.JMenuItem();
        sub_dependente = new javax.swing.JMenuItem();
        sub_funcionario = new javax.swing.JMenuItem();
        sub_gravarMidias1 = new javax.swing.JMenu();
        item_cd = new javax.swing.JMenuItem();
        item_dvd = new javax.swing.JMenuItem();
        itemGame = new javax.swing.JMenuItem();
        sub_pagametoAntecipado = new javax.swing.JMenuItem();
        menu_locacao = new javax.swing.JMenu();
        sub_registrarLocacao = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SIS LOCADORA");
        setBackground(new java.awt.Color(204, 204, 204));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/fita.png"))); // NOI18N
        jLabel3.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        arvore.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Escolha");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Arquivo");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Sair");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Tabelas");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Gerar Base de Dados");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Cadastros");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Categoria");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Cliente");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Cd");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("DvD");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Dependente");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Funcionário");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Game");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Pagamento Antecipado");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Locação");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Registrar");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        arvore.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        arvore.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                arvoreMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(arvore);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 495, Short.MAX_VALUE)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
                .addGap(11, 11, 11))
        );

        jToolBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar1.setRollover(true);
        jToolBar1.setAutoscrolls(true);
        jToolBar1.setInheritsPopupMenu(true);

        btnGerarBase.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/gerarBase.png"))); // NOI18N
        btnGerarBase.setToolTipText("Gerar Base de Dados");
        btnGerarBase.setFocusable(false);
        btnGerarBase.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGerarBase.setMargin(new java.awt.Insets(2, 20, 2, 20));
        btnGerarBase.setOpaque(false);
        btnGerarBase.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGerarBase.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGerarBaseActionPerformed(evt);
            }
        });
        jToolBar1.add(btnGerarBase);

        btnFuncionario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/funcionario.png"))); // NOI18N
        btnFuncionario.setToolTipText("Cadastrar/Consultar Funcionário");
        btnFuncionario.setFocusable(false);
        btnFuncionario.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnFuncionario.setMargin(new java.awt.Insets(2, 20, 2, 20));
        btnFuncionario.setOpaque(false);
        btnFuncionario.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnFuncionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFuncionarioActionPerformed(evt);
            }
        });
        jToolBar1.add(btnFuncionario);

        btnDependente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/dependentes.png"))); // NOI18N
        btnDependente.setToolTipText("Cadastrar/Consultar Dependente");
        btnDependente.setFocusable(false);
        btnDependente.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnDependente.setMargin(new java.awt.Insets(2, 20, 2, 20));
        btnDependente.setOpaque(false);
        btnDependente.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnDependente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDependenteActionPerformed(evt);
            }
        });
        jToolBar1.add(btnDependente);

        btnClientes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/clientes.png"))); // NOI18N
        btnClientes.setToolTipText("Cadastrar/Consultar Clientes");
        btnClientes.setFocusable(false);
        btnClientes.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnClientes.setMargin(new java.awt.Insets(2, 20, 2, 20));
        btnClientes.setOpaque(false);
        btnClientes.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnClientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnClientesActionPerformed(evt);
            }
        });
        jToolBar1.add(btnClientes);

        btnCategoria.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/categoria.png"))); // NOI18N
        btnCategoria.setToolTipText("Cadastrar/Consultar Categoria");
        btnCategoria.setFocusable(false);
        btnCategoria.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCategoria.setMargin(new java.awt.Insets(2, 20, 2, 20));
        btnCategoria.setOpaque(false);
        btnCategoria.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCategoriaActionPerformed(evt);
            }
        });
        jToolBar1.add(btnCategoria);

        btnCd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/cd.png"))); // NOI18N
        btnCd.setToolTipText("Cadastrar/Consultar CD");
        btnCd.setFocusable(false);
        btnCd.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCd.setMargin(new java.awt.Insets(2, 20, 2, 20));
        btnCd.setOpaque(false);
        btnCd.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCdActionPerformed(evt);
            }
        });
        jToolBar1.add(btnCd);

        btnDvd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/dvd.png"))); // NOI18N
        btnDvd.setToolTipText("Cadastrar/Consultar DVD");
        btnDvd.setFocusable(false);
        btnDvd.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnDvd.setMargin(new java.awt.Insets(2, 20, 2, 20));
        btnDvd.setOpaque(false);
        btnDvd.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnDvd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDvdActionPerformed(evt);
            }
        });
        jToolBar1.add(btnDvd);

        btnGames.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/Games.png"))); // NOI18N
        btnGames.setToolTipText("Cadastrar/Consultar Games");
        btnGames.setFocusable(false);
        btnGames.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGames.setMargin(new java.awt.Insets(2, 20, 2, 20));
        btnGames.setOpaque(false);
        btnGames.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGames.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGamesActionPerformed(evt);
            }
        });
        jToolBar1.add(btnGames);

        btnPagamentoAntecipado.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/pagamento.png"))); // NOI18N
        btnPagamentoAntecipado.setToolTipText("Cadastrar/Consultar Pagamento Antecipado");
        btnPagamentoAntecipado.setFocusable(false);
        btnPagamentoAntecipado.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnPagamentoAntecipado.setMargin(new java.awt.Insets(2, 20, 2, 20));
        btnPagamentoAntecipado.setOpaque(false);
        btnPagamentoAntecipado.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnPagamentoAntecipado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPagamentoAntecipadoActionPerformed(evt);
            }
        });
        jToolBar1.add(btnPagamentoAntecipado);

        btnLocacao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/locacao.png"))); // NOI18N
        btnLocacao.setToolTipText("Cadastrar/Consultar Pagamento Locação");
        btnLocacao.setFocusable(false);
        btnLocacao.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnLocacao.setMargin(new java.awt.Insets(2, 20, 2, 20));
        btnLocacao.setOpaque(false);
        btnLocacao.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnLocacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLocacaoActionPerformed(evt);
            }
        });
        jToolBar1.add(btnLocacao);

        btnSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/sair.png"))); // NOI18N
        btnSair.setToolTipText("Sair");
        btnSair.setDefaultCapable(false);
        btnSair.setFocusable(false);
        btnSair.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnSair.setMargin(new java.awt.Insets(2, 20, 2, 20));
        btnSair.setOpaque(false);
        btnSair.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });
        jToolBar1.add(btnSair);

        menu_principal.setBackground(new java.awt.Color(255, 255, 255));
        menu_principal.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "SISTEMA LOCADORA POS-ES-JAVA", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 14))); // NOI18N
        menu_principal.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N

        menu_arquivo.setBorder(null);
        menu_arquivo.setText("Arquivo");
        menu_arquivo.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N

        sub_sair.setText("Sair");
        sub_sair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sub_sairActionPerformed(evt);
            }
        });
        menu_arquivo.add(sub_sair);

        menu_principal.add(menu_arquivo);

        menu_tabelas.setBorder(null);
        menu_tabelas.setText("Tabelas");
        menu_tabelas.setFont(new java.awt.Font("Times New Roman", 0, 14));

        sub_gerarBase.setText("Gerar Base de Dados");
        sub_gerarBase.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sub_gerarBaseActionPerformed(evt);
            }
        });
        menu_tabelas.add(sub_gerarBase);

        menu_principal.add(menu_tabelas);

        menu_cadastros.setBorder(null);
        menu_cadastros.setText("Cadastros");
        menu_cadastros.setFont(new java.awt.Font("Times New Roman", 0, 14));

        sub_categoria.setText("Categorias");
        sub_categoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sub_categoriaActionPerformed(evt);
            }
        });
        menu_cadastros.add(sub_categoria);

        sub_cliente.setText("Cliente");
        sub_cliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sub_clienteActionPerformed(evt);
            }
        });
        menu_cadastros.add(sub_cliente);

        sub_dependente.setText("Dependente");
        sub_dependente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sub_dependenteActionPerformed(evt);
            }
        });
        menu_cadastros.add(sub_dependente);

        sub_funcionario.setText("Funcionário");
        sub_funcionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sub_funcionarioActionPerformed(evt);
            }
        });
        menu_cadastros.add(sub_funcionario);

        sub_gravarMidias1.setText("Mídias >>");

        item_cd.setText("CD");
        item_cd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                item_cdActionPerformed(evt);
            }
        });
        sub_gravarMidias1.add(item_cd);

        item_dvd.setText("Dvd");
        item_dvd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                item_dvdActionPerformed(evt);
            }
        });
        sub_gravarMidias1.add(item_dvd);

        itemGame.setText("Games");
        itemGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemGameActionPerformed(evt);
            }
        });
        sub_gravarMidias1.add(itemGame);

        menu_cadastros.add(sub_gravarMidias1);

        sub_pagametoAntecipado.setText("Pagamento Antecipado");
        sub_pagametoAntecipado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sub_pagametoAntecipadoActionPerformed(evt);
            }
        });
        menu_cadastros.add(sub_pagametoAntecipado);

        menu_principal.add(menu_cadastros);

        menu_locacao.setBorder(null);
        menu_locacao.setText("Locação");
        menu_locacao.setFont(new java.awt.Font("Times New Roman", 0, 14));

        sub_registrarLocacao.setText("Registrar");
        sub_registrarLocacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sub_registrarLocacaoActionPerformed(evt);
            }
        });
        menu_locacao.add(sub_registrarLocacao);

        menu_principal.add(menu_locacao);

        setJMenuBar(menu_principal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 876, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleName("Formulário Central");

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-892)/2, (screenSize.height-445)/2, 892, 445);
    }// </editor-fold>//GEN-END:initComponents

    private void sub_gerarBaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sub_gerarBaseActionPerformed

        int ret = JOptionPane.showConfirmDialog(this, "Deseja criar a base de dados?", "Gerar Base de Dados!",
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (ret == JOptionPane.OK_OPTION) {
            int ret2 = JOptionPane.showConfirmDialog(this, "Isso irá apagar toda a base de dados existente", "Dados Serão apagados!",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE);

            if (ret2 == JOptionPane.OK_OPTION) {
                Configuration cfg = new Configuration().configure();
                SchemaExport ex = new SchemaExport(cfg);
                ex.create(true, true);
            }

        }

    }//GEN-LAST:event_sub_gerarBaseActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        int ret = JOptionPane.showConfirmDialog(this, "Deseja Fechar?", "Sair",
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);

        if (ret == JOptionPane.OK_OPTION) {
            System.exit(0);
        }
    }//GEN-LAST:event_btnSairActionPerformed

    private void btnGerarBaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGerarBaseActionPerformed
        int ret = JOptionPane.showConfirmDialog(this, "Deseja criar a base de dados?", "Gerar Base de Dados!",
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (ret == JOptionPane.OK_OPTION) {
            int ret2 = JOptionPane.showConfirmDialog(this, "Isso irá apagar toda a base de dados existente", "Dados Serão apagados!",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE);

            if (ret2 == JOptionPane.OK_OPTION) {
                Configuration cfg = new Configuration().configure();
                SchemaExport ex = new SchemaExport(cfg);
                ex.create(true, true);
            }

        }
    }//GEN-LAST:event_btnGerarBaseActionPerformed

    private void sub_sairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sub_sairActionPerformed
        int ret = JOptionPane.showConfirmDialog(this, "Deseja Fechar?", "Sair",
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);

        if (ret == JOptionPane.OK_OPTION) {
            System.exit(0);
        }
    }//GEN-LAST:event_sub_sairActionPerformed

    private void item_cdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_item_cdActionPerformed
        JOptionPane.showMessageDialog(this, "Estou sem tratamento de erros\n porém o Sr. Leandro irá me corrigir!");
        CadCd cad = new CadCd(this, rootPaneCheckingEnabled);
        cad.setVisible(true);
    }//GEN-LAST:event_item_cdActionPerformed

    private void item_dvdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_item_dvdActionPerformed
        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. Bruno \nainda não me desenvolveu!");
    }//GEN-LAST:event_item_dvdActionPerformed

    private void itemGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemGameActionPerformed
        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. Roboson Vitor \nainda não me desenvolveu!");
    }//GEN-LAST:event_itemGameActionPerformed

    private void sub_categoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sub_categoriaActionPerformed
        JOptionPane.showMessageDialog(this, "Estou com alguns erros \n porém o Sr. Welinton irá me corrigir!");
        CadCategorias cat = new CadCategorias(this, rootPaneCheckingEnabled);
        cat.setVisible(true);
    }//GEN-LAST:event_sub_categoriaActionPerformed

    private void btnFuncionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFuncionarioActionPerformed
        
        CadFuncionarios c = new CadFuncionarios(this, rootPaneCheckingEnabled);
        c.setVisible(true);
    }//GEN-LAST:event_btnFuncionarioActionPerformed

    private void btnClientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClientesActionPerformed
        JOptionPane.showMessageDialog(this, "Sr. Giovani está implementando!");
        CadCliente cad = new CadCliente(this, rootPaneCheckingEnabled);
        cad.setVisible(true);
    }//GEN-LAST:event_btnClientesActionPerformed

    private void btnDependenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDependenteActionPerformed
        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. Richard \nainda não me desenvolveu!");
    }//GEN-LAST:event_btnDependenteActionPerformed

    private void btnCdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCdActionPerformed
        JOptionPane.showMessageDialog(this, "Estou sem tratamento de erros\n porém o Sr. Leandro irá me corrigir!");
        CadCd cad = new CadCd(this, rootPaneCheckingEnabled);
        cad.setVisible(true);
    }//GEN-LAST:event_btnCdActionPerformed

    private void btnDvdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDvdActionPerformed
        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. Bruno \nainda não me desenvolveu!");
    }//GEN-LAST:event_btnDvdActionPerformed

    private void btnGamesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGamesActionPerformed
        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. Robson Vitor \nainda não me desenvolveu!");
    }//GEN-LAST:event_btnGamesActionPerformed

    private void btnPagamentoAntecipadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPagamentoAntecipadoActionPerformed
        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. José Vitor \nainda não me desenvolveu!");
    }//GEN-LAST:event_btnPagamentoAntecipadoActionPerformed

    private void btnLocacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLocacaoActionPerformed
        JOptionPane.showMessageDialog(this, "O Sr. Eder e a Sra, Cintia vão deixa-los\n babando com o frame Pagamento!");
    }//GEN-LAST:event_btnLocacaoActionPerformed

    private void sub_registrarLocacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sub_registrarLocacaoActionPerformed
        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. Eder Alves \ne a Sra Cíntia \nainda não me desenvolveram!");
    }//GEN-LAST:event_sub_registrarLocacaoActionPerformed

    private void sub_clienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sub_clienteActionPerformed
        JOptionPane.showMessageDialog(this, "O Sr. Giovani está desenvolvendo!");
        CadCliente cad = new CadCliente(this, rootPaneCheckingEnabled);
        cad.setVisible(true);
    }//GEN-LAST:event_sub_clienteActionPerformed

    private void sub_dependenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sub_dependenteActionPerformed
        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. Richard \nainda não me desenvolveu!");
    }//GEN-LAST:event_sub_dependenteActionPerformed

    private void sub_funcionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sub_funcionarioActionPerformed
        
    }//GEN-LAST:event_sub_funcionarioActionPerformed

    private void sub_pagametoAntecipadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sub_pagametoAntecipadoActionPerformed
        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. José Vitor \nainda não me desenvolveu!");
    }//GEN-LAST:event_sub_pagametoAntecipadoActionPerformed

    private void btnCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCategoriaActionPerformed
        JOptionPane.showMessageDialog(this, "Estou com alguns erros \n porém o Sr. Welinton irá me corrigir!");
        CadCategorias cat = new CadCategorias(this, rootPaneCheckingEnabled);
        cat.setVisible(true);
    }//GEN-LAST:event_btnCategoriaActionPerformed

    private void arvoreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_arvoreMouseClicked
        try {
            if (evt.getClickCount() == 1) {
                /*Clicando uma vez obtenho o caminho do nodo TreePath até a raiz usando o método getPathForLocation que retorna o nodo
                da árvore que se encontra em determinado ponto(coordenada x e y obtida do clique do mouse). A partir do caminho, obtem-se
                o último componente dele o nodo clicado. Por fim obtenho a descrição do nodo*/
                TreePath caminho = arvore.getPathForLocation(evt.getX(), evt.getY());
                try {
                    String folha = (String) ((DefaultMutableTreeNode) caminho.getLastPathComponent()).getUserObject();
                    if (folha.equals("Sair")) {
                        int ret = JOptionPane.showConfirmDialog(this, "Deseja Fechar?", "Sair",
                                JOptionPane.OK_CANCEL_OPTION,
                                JOptionPane.QUESTION_MESSAGE);

                        if (ret == JOptionPane.OK_OPTION) {
                            System.exit(0);
                        }
                    }
                    if (folha.equals("Gerar Base de Dados")) {
                        int ret = JOptionPane.showConfirmDialog(this, "Deseja criar a base de dados?", "Gerar Base de Dados!",
                                JOptionPane.OK_CANCEL_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                        if (ret == JOptionPane.OK_OPTION) {
                            int ret2 = JOptionPane.showConfirmDialog(this, "Isso irá apagar toda a base de dados existente", "Dados Serão apagados!",
                                    JOptionPane.OK_CANCEL_OPTION,
                                    JOptionPane.QUESTION_MESSAGE);

                            if (ret2 == JOptionPane.OK_OPTION) {
                                Configuration cfg = new Configuration().configure();
                                SchemaExport ex = new SchemaExport(cfg);
                                ex.create(true, true);
                            }

                        }
                    }
                    if (folha.equals("Categoria")) {
                        JOptionPane.showMessageDialog(this, "Estou com alguns erros \n porém o Sr. Welinton irá me corrigir!");
                        CadCategorias cat = new CadCategorias(this, rootPaneCheckingEnabled);
                        cat.setVisible(true);
                    }
                    if (folha.equals("Cliente")) {
                        CadCliente cad = new CadCliente(this, rootPaneCheckingEnabled);
                        cad.setVisible(true);
                    }
                    if (folha.equals("Dependente")) {
                        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. Richard \nainda não me desenvolveu!");
                    }
                    if (folha.equals("Cd")) {
                        JOptionPane.showMessageDialog(this, "Estou sem tratamento de erros\n porém o Sr. Leandro irá me corrigir!");
                        CadCd cad = new CadCd(this, rootPaneCheckingEnabled);
                        cad.setVisible(true);
                    }
                    if (folha.equals("DvD")) {
                        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. Bruno \nainda não me desenvolveu!");
                    }
                    if (folha.equals("Game")) {
                        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. Robson Vitor \nainda não me desenvolveu!");
                    }
                    if (folha.equals("Pagamento Antecipado")) {
                        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. José Vitor \nainda não me desenvolveu!");
                    }
                    if (folha.equals("Registrar")) {
                        JOptionPane.showMessageDialog(this, "Infelizmente o Sr. Eder Alves \ne a Sra Cíntia \nainda não me desenvolveram!");
                    }

                } catch (ClassCastException e) {
                }
            }
        } catch (Exception e) {
        }

    }//GEN-LAST:event_arvoreMouseClicked
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTree arvore;
    private javax.swing.JButton btnCategoria;
    private javax.swing.JButton btnCd;
    private javax.swing.JButton btnClientes;
    private javax.swing.JButton btnDependente;
    private javax.swing.JButton btnDvd;
    private javax.swing.JButton btnFuncionario;
    private javax.swing.JButton btnGames;
    private javax.swing.JButton btnGerarBase;
    private javax.swing.JButton btnLocacao;
    private javax.swing.JButton btnPagamentoAntecipado;
    private javax.swing.JButton btnSair;
    private javax.swing.JMenuItem itemGame;
    private javax.swing.JMenuItem item_cd;
    private javax.swing.JMenuItem item_dvd;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenu menu_arquivo;
    private javax.swing.JMenu menu_cadastros;
    private javax.swing.JMenu menu_locacao;
    private javax.swing.JMenuBar menu_principal;
    private javax.swing.JMenu menu_tabelas;
    private javax.swing.JMenuItem sub_categoria;
    private javax.swing.JMenuItem sub_cliente;
    private javax.swing.JMenuItem sub_dependente;
    private javax.swing.JMenuItem sub_funcionario;
    private javax.swing.JMenuItem sub_gerarBase;
    private javax.swing.JMenu sub_gravarMidias1;
    private javax.swing.JMenuItem sub_pagametoAntecipado;
    private javax.swing.JMenuItem sub_registrarLocacao;
    private javax.swing.JMenuItem sub_sair;
    // End of variables declaration//GEN-END:variables
}
